window.onload=function(){
    var myswiper1 = new Swiper('.tcgswiper-container', {
        slidesPerView: 'auto'
    });
    var myswiper2 = new Swiper('.tcggamelist-swiper', {
        effect : 'cube',
        cubeEffect: {
            slideShadows: false,
            shadow: false,
            shadowOffset: 100,
            shadowScale: 0.6
        },
        slidesPerView: 'auto',
        on:{
            init: function(){
                $('.tcgswiper-container .swiper-slide').eq(this.activeIndex).addClass("active").siblings().removeClass("active")
            }, 
            slideChangeTransitionEnd: function(){
                $('.tcgswiper-container .swiper-slide').eq(this.activeIndex).addClass("active").siblings().removeClass("active")
                myswiper1.slideTo(this.activeIndex)
            }
        }
    });
    $('.tcgswiper-container .swiper-slide').click(function(){
        $(this).addClass("active").siblings().removeClass("active")
        myswiper1.slideTo($(this).index())
        myswiper2.slideTo($(this).index())
    })
}

var app=new Vue({
    el:'.mtcggame-container',
    data(){
        return {
            exchange: { //兑换配置项
                defaultcoin: 'HPS', //默认币种
                isshowcoinarr: false //是否展示下拉选
            },
            userinfo:{ //用户信息
                banlance:'',//用户余额
                myagbanlance:0,//我的TCG积分余额
                lottoName:'Lobby', //彩种名称code 默认大厅
                viewName:'Lobby', //彩票页面，大厅页
                gameurl:'' //TCG彩票地址
            }
        }
    },
    created() {
        this.setRem(27)
        this.getagBalance()
    },
    methods:{
        setRem(itemNum) { //设置字体rem
            let size = itemNum || 36;
            window.onresize = remSize;
            remSize();
            function remSize() {
                let html = document.getElementsByTagName('html')[0], w = html.clientWidth;
                w = w > 768 ? 768 : w;
                html.style.fontSize = w / size + 'px'
            }
        },
        getagBalance() {//获取当前用户TCG分
            let params = {
                coin: this.exchange.defaultcoin
            }
            axios.post('/tcgBalance', params).then((res) => {
                if (res.data.code == 200) {
                    if(res.data.data.status==0){
                        this.userinfo.myagbanlance = res.data.data.balance
                    }
                }
            })
        },
        toggletcgurl(lottoName,viewName){
            if(!lottoName){
                return 
            }
            this.userinfo.lottoName=lottoName
            this.userinfo.viewName=viewName
            this.getlaunchGame()
        },
        getlaunchGame(){ //获取游戏大厅
            let params={
                coin:this.exchange.defaultcoin,
                lottoName:this.userinfo.lottoName,
                pageName:this.userinfo.viewName,
                lottoType:'Elott_Traditional_Mobile_V2'
            }
            axios.post('/tcgGameurl',params).then((res) => {
                if(res.data.code==200){
                    if(res.data.data.status==0){
                        location.href='/m/mtcggameurl'
                    }
                }
            })
        },
        changeexchangecoin(cointype,banlance){//用户点击更换币种
            this.exchange.defaultcoin=cointype
            this.exchange.isshowcoinarr=false
            this.userinfo.banlance=banlance
            this.getagBalance()
        }
    }
})